package com.example.monit.service;

import com.example.monit.bean.Replay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

@Service
public class ReplayServiceImpl implements ReplayService {
    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public void report(Replay replay) {
        mongoTemplate.insert(replay);
    }

    @Override
    public Replay getReplayByEventId(String eventId) {
        Query query = Query.query(Criteria.where("eventId").is(eventId));
        Replay replay = mongoTemplate.findOne(query, Replay.class);
        return replay;
    }
}
